import { createApp } from 'vue'
import { createPinia } from 'pinia'
import App from './App.vue'
import router from './router'
import { siteConfig } from './config/site'
import { validateConfig } from './utils/configValidator'
import { setupConfigHotReload } from './utils/config'
import './styles/main.css'

// 验证配置
const { valid, errors } = validateConfig(siteConfig)
if (!valid) {
  console.error('配置验证失败，错误详情：', errors)
  if (import.meta.env.DEV) {
    const errorMessages = errors.map(err => `${err.path}: ${err.message}`).join('\n')
    throw new Error(`配置验证失败:\n${errorMessages}`)
  }
}

// 开发环境下启用配置热重载
if (import.meta.env.DEV) {
  setupConfigHotReload()
}

const app = createApp(App)
const pinia = createPinia()

// 全局错误处理
app.config.errorHandler = (err, vm, info) => {
  if (err.name === 'ConfigError') {
    console.error('Configuration error:', err.message, err.errors)
  } else {
    console.error('Application error:', err, info)
  }
}

app.use(pinia)
app.use(router)
app.mount('#app') 